var productList;
var localData =[
    {"id": 1,"productName": "户外啥的乱七八糟1","productId":"hw1325481","state":1,"phone":15868721752,"nickName":"shaofancun","dataTime":'2016-1-12 9:05'},
    {"id": 2,"productName": "户外啥的乱七八糟2","productId":"hw1325481","state":0,"phone":15868721752,"nickName":"ggg","dataTime":'2016-1-12 9:05'},
    {"id": 3,"productName": "户外啥的乱七八糟3","productId":"hw1325481","state":1,"phone":15868721752,"nickName":"else","dataTime":'2016-1-12 9:05'},
    {"id": 4,"productName": "户外啥的乱七八糟4","productId":"hw1325481","state":1,"phone":15868721752,"nickName":"www","dataTime":'2016-1-12 9:05'}
    ];
$(function () {
    if($('#productList').length>0){
        productList = $.fn.bsgrid.init('productList', {
            localData: localData,   //本地json
            //url:'',               //数据地址
            // autoLoad: false,
            pageSizeSelect: true,
            pageSize: 10,
            stripeRows: true,
            displayBlankRows: false
        });
    }
});
//productList表格相关方法
var pro={
	//产品状态
    state:function(record, rowIndex, colIndex, options){
    	var state=productList.getRecordIndexValue(record, 'state');
        if(state==1) return '<span class="sui-text-success">已上架</span>';
        else if(state==0) return '<span class="sui-text-disabled">已下架</span>';
    },
    //表格操作
    operate:function(record, rowIndex, colIndex, options){
        var id=productList.getRecordIndexValue(record, 'id');
        var operate='';
        operate+='<a href="productEdit.html?id=' + id + '">编辑</a> <a href="javascript:;" onclick="pro.del(' + id + ')">删除</a>';
        return operate;
    },
    //搜索
    search:function(){
        var form=$("#seach").serializeArray();
        productList.search(form);
    },
    //删除产品
    del:function(id){
        table.del({
            "id":id,
            "url":'../../testApi/dels.php'
        })
    },
    //删除勾选产品
    delCheck:function(){
        var ids = productList.getCheckedValues("id");
        table.delCheck({
            "ids":ids,
            "url":'../../testApi/dels.php'
        })   
    }  
}
$(document).on('change','.fileImg',function(e){
	$(this).uploadimg(this,e);
});
$("#productEdit").validate({
	rules:{
		name:{required:true},
		productId:{required:true},
        proClass:{required:true},
		price:{required:true,number:true},
		phone:{required:true,mobile:true}
	}
});
if($("#teletext").length>0){
	KindEditor.ready(function(k){
		k.create("#teletext");
		k.create("#notice");
	});
}
